import java.util.Scanner;
import java.util.Arrays;

public class MAX {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        // 读取N和K
        int N = scanner.nextInt();
        int K = scanner.nextInt();

        // 读取数组元素
        int[] array = new int[N];
        for (int i = 0; i < N; i++) {
            array[i] = scanner.nextInt();
        }

        // 计算最大Dk值
        int maxDk = maxDifference(array, N, K);

        // 输出结果
        System.out.println(maxDk);

        scanner.close();
    }

    private static int maxDifference(int[] array, int N, int K) {
        int maxDk = 0;

        // 遍历数组，计算每个K区间的最大差值
        for (int i = 0; i <= N - K; i++) {
            // 计算当前K区间的最大值和最小值
            int max = array[i];
            int min = array[i];
            for (int j = i; j < i + K; j++) {
                if (array[j] > max) {
                    max = array[j];
                }
                if (array[j] < min) {
                    min = array[j];
                }
            }
            // 计算当前K区间的最大差值，并更新maxDk
            int currentDk = Math.abs(max - min);
            if (currentDk > maxDk) {
                maxDk = currentDk;
            }
        }

        return maxDk;
    }
}